<?php

namespace app\admin\controller;

use app\common\controller\Backend;
use think\Session;
use think\Db;
/**
 * zc_plan 计划表 --张威
 *
 * @icon fa fa-circle-o
 */
class Planlist extends Backend
{

    /**
     * Plan模型对象
     * @var \app\admin\model\Plan
     */
    protected $model = null;
    protected $dataLimit = 'auth'; //默认基类中为false，表示不启用，可额外使用auth和personal两个值
    protected $dataLimitField = 'admin_id'; //数据关联字段,当前控制器对应的模型表中必须存在该字段
    protected $admin_id = 0;
    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\Plan;
        $this->view->assign("stateList", $this->model->getStateList());
        $this->view->assign("statusList", $this->model->getStatusList());
        $this->admin_id = Session::get("admin")['id'];
    }

    public function index()
    {
        if ($this->request->isAjax())
        {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $total = $this->model
                ->where($where)
                ->order($sort, $order)
                ->count();
            $list = $this->model
                ->where($where)
                ->order($sort, $order)
                ->limit($offset, $limit)
                ->select();
            $result = array("total" => $total, "rows" => $list);
            return json($result);
        }
        return $this->view->fetch();
    }

}
